﻿using UnityEngine;
using System.Collections;

public class AccelerometerReader : MonoBehaviour {

    public float updateInterval = 1.0f / 60.0f;     // 60 reads per second
    public float lowPassKernelWidth = 1.0f;         // in seconds

    public Vector3 lowPassValue = Vector3.zero;    // Last calculated value
    private float lowPassFilterFactor = 1.0f;       // Used in the lerp

	// Use this for initialization
	void Start () {

        lowPassFilterFactor = updateInterval / lowPassKernelWidth;
        lowPassValue = Input.acceleration;

	}
	
	// Update is called once per frame
	void Update () {
	
        // Low-pass filtering
        LowPassFilterAccelerometer();
    }

    private Vector3 LowPassFilterAccelerometer()
    {
        lowPassValue = Vector3.Lerp(lowPassValue, Input.acceleration, lowPassFilterFactor);
        return lowPassValue;
    }

    void OnGUI()
    {
        //GUI.Label(new Rect(Screen.width / 2 - 100, 10, 200, 50), lowPassValue.ToString("F3"), new GUIStyle() { fontSize = 20 });

    }


}
